package logic;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import objects.*;
import tiddly.*;

public class Wrapper {

	public static void createTiddly(Entity tiddly){
		if (tiddly.getClass().equals(Char.class)){
			tiddly.getID();
			String name = tiddly.getName();
			String typ = tiddly.getType();
			((Char) tiddly).getLocation();
			String desc = ((Char) tiddly).getDesc();

			String newTiddly = "<div title=\""+name+"\" creator=\"Nobody\" modifier=\"Nobody\" created=\""+getDate()+"\" tags=\""+typ+"\" changecount=\"1\">\n<pre>"+TiddlyHandler.encoder(desc)+"</pre>\n</div>\n";
			TiddlyHandler.writeData(newTiddly);
		}
		else if (tiddly.getClass().equals(Location.class)){
			tiddly.getID();
			String name = tiddly.getName();
			String typ = tiddly.getType();
			((Location) tiddly).getX();
			((Location) tiddly).getY();
			String desc = ((Location) tiddly).getDesc();

			String newTiddly = "<div title=\""+name+"\" creator=\"Nobody\" modifier=\"Nobody\" created=\""+getDate()+"\" tags=\""+typ+"\" changecount=\"1\">\n<pre>"+TiddlyHandler.encoder(desc)+"</pre>\n</div>\n";
			TiddlyHandler.writeData(newTiddly);
		}
		else if (tiddly.getClass().equals(Item.class)){
			tiddly.getID();
			String name = tiddly.getName();
			String typ = tiddly.getType();
			((Item) tiddly).getLocation();
			((Item) tiddly).getCharacter();
			String desc = ((Item) tiddly).getDescription();

			String newTiddly = "<div title=\""+name+"\" creator=\"Nobody\" modifier=\"Nobody\" created=\""+getDate()+"\" tags=\""+typ+"\" changecount=\"1\">\n<pre>"+TiddlyHandler.encoder(desc)+"</pre>\n</div>\n";
			TiddlyHandler.writeData(newTiddly);
		}
		else if (tiddly.getClass().equals(Tiddler.class)){
			String title = ((Tiddler)tiddly).getTitle();
			String creator = ((Tiddler)tiddly).getCreator();
			String modifier= ((Tiddler)tiddly).getModifier();
			long created = ((Tiddler)tiddly).getCreated();
			String tags = ((Tiddler)tiddly).getTags();
			int changeCount = ((Tiddler)tiddly).getChangeCount();
			String desc = ((Tiddler)tiddly).getDesc();
			

			String newTiddly = "<div title=\""+title+"\" creator=\""+creator+"\" modifier=\""+modifier+"\" created=\""+created+"\" tags=\""+tags+"\" changecount=\""+changeCount+"\">\n<pre>"+TiddlyHandler.encoder(desc)+"</pre>\n</div>\n";
			TiddlyHandler.writeData(newTiddly);
		}
	}
	
	public static long getDate(){
		
		DateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
		String formattedDate = df.format(new Date());
		long newForm = Long.parseLong(formattedDate);
		
		return newForm;
	}
}
